package org.breezeiot.protodecode.enums;

/**
 * 1-电<br>
 * 2-水<br>
 *
 * @author armording
 */
public enum EnergyTypeEnum  {
    POWER(1, "电力"),
    WATER(2, "水"),
    HOT_WATER(3, "热水"),
    HEAT(4, "热能"),
    GAS(5, "天然气");

    private final int value;
    private final String text;

    EnergyTypeEnum(int value, String text) {
        this.value = value;
        this.text = text;
    }

    public int getValue() {
        return value;
    }

    public String getText() {
        return text;
    }

    public static String getText(short value) {
        EnergyTypeEnum em = getEnmuByValue(value);
        return em == null ? null : em.getText();
    }

    public short getShortValue() {
        return (short) value;
    }

    /**
     * 通过传入的字符串匹配枚举，传入值
     *
     * @param value
     * @return
     */
    public static EnergyTypeEnum getEnmuByValue(short value) {
        for (EnergyTypeEnum lowCommType : EnergyTypeEnum.values()) {
            if (value == lowCommType.getValue()) {
                return lowCommType;
            }
        }
        return null;
    }

    /**
     * 获取能源种类对应的费用名称
     */
    public static String getFeeText(short value) {
        EnergyTypeEnum em = getEnmuByValue(value);
        String name = null;
        if (EnergyTypeEnum.POWER == em) {
            name = "电费";
        } else if (EnergyTypeEnum.WATER == em) {
            name = "水费";
        } else if (EnergyTypeEnum.HEAT == em) {
            name = "热量费";
        } else {
            name = em.getText() + "费";
        }
        return name;
    }

    @Override
    public String toString() {
        return text;
    }

}
